/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.Impl;

import com.startup.musicstore.model.Album;
import com.startup.musicstore.model.AlbumCategory;
import com.startup.musicstore.model.Track;
import com.startup.musicstore.services.SampleURLService;
import com.startup.musicstore.services.crud.AlbumCategoryCrudService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author linda
 */
@Service("sampleURLService")
@Transactional
public class SampleURLServiceImpl implements SampleURLService{
    
    @Autowired
    private AlbumCategoryCrudService albumCategoryCrudService;

    @Override
    public String getSampleURL(Long albumID, int trackNumber) {
        String URL = "";
        
        List<AlbumCategory> categories = albumCategoryCrudService.findAll();
        for(int a = 0; categories.size() > 0; a++)
        {
            AlbumCategory cat = categories.get(a);
            List<Album> albums = cat.getAlbums();
            for(int b=0; albums.size() > 0; b++)
            {
                Album al = albums.get(b);
                List<Track> tracks = al.getTracks();
                for(int c=0; tracks.size()>0; c++)
                {
                    Track tr = tracks.get(c);
                    if(tr.getTrackNumber() == trackNumber)
                    {
                        URL = tr.getSample().getSampleURL();
                        break;
                    }
                }
            }
            
        }
        
        
        return URL;
        
    }
    
}
